<link href="/static/public/layer/src/css/layui.css" rel="stylesheet">
<link href="/static/public/css/style.css" rel="stylesheet">
<script type="text/javascript" src="/static/manage/js/jquery-1.7.2.min.js"></script>
<script src="/static/public/layer/src/layui.js"></script>
<div class="dm-tree" style="padding:10px;">
	<{foreach from=$subject item=item}>
    <dl>
        <dt><a></a><span class="t_s"><{$item['title']}></span></dt>
        <{if $item.children}>
        <dd>
        	<{foreach from=$item.children item=ditem}>
        	<{if $ditem['children'] > 0}>
            <dl>
            <dt class="pdt" pid="<{$ditem.id}>"><a></a><span class="t_s"><{$ditem['title']}></span></dt>
            </dl>
            <{else}>
            <div class="item"><a class="not_a"></a><label><input type="radio" name="ids[]" title="<{$ditem['title']}>" value="<{$ditem.id}>" /><span class="d_s"><{$ditem['title']}></span></label></div>
            <{/if}>
            <{/foreach}>
        </dd>
        <{/if}>
    </dl>
    <{/foreach}>
    <a id="choice" class="layui-btn layui-btn-primary " style="">确定</a>
</div>
<{include file="footer.html"}>
<script>
$(document).on("click","dt",function(){
	var _this = $(this);
	_this.toggleClass('curr_tree');
	_this.siblings('dd').toggle();
	var pid = _this.attr("pid");
	if(typeof(pid) != "undefined" && pid > 0){
		_this.attr("pid", "0");
		$.ajax({
			url:"/tk_accounts_subject/ajax_get_subject_children",
			type:"post",
			dataType:"json",
			data:"pid="+pid,
			success:function(res){
				if(res.code == 1){
					var html = '<dd style="display:block;"><div class="item"><dl>';
					$.each(res.children, function(i, obj){
						if(obj.children == 0){
							html += '<div class="item"><a class="not_a"></a><label><input type="radio" name="ids[]" title="'+obj.title+'" value="'+obj.id+'" /><span class="d_s">'+obj.title+'</span></label></div>';
						}else{
							html += '<dt class="pdt" pid="'+obj.id+'"><a></a><span class="t_s">'+obj.title+'</span></dt>';
						}
					})
					html += '</dl></div></dd>';
					_this.after(html);
				}
			}
		});
	}
})
layui.use(['form', 'jquery', 'layer'], function(){
    var form = layui.form(),$ = layui.jquery, layer = layui.layer;
    $("#choice").click(function(){
    	var select_radio = $("input[name='ids[]']:checked");
    	$(window.parent.document).find("#hidden_id").val(select_radio.val())
    	$(window.parent.document).find("#hidden_id_text").val(select_radio.attr("title"))
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
        
    })
});
</script>